const http = require("http");
const fs = require("fs");
const path = require("path");

const dirPath = path.join(__dirname,process.argv[2]);

http.createServer((req,res) => {
    res.setHeader('content-type','text/html;charset=utf-8');
    fs.exists(dirPath,function(exists) {
        if(exists == true) {
            const readable = fs.createReadStream(dirPath);
            readable.pipe(res)
        }
        else {
            console.log("路径文件不存在");
            const readerpath = path.join(__dirname,"/fileReader1.js");
            const readPath = fs.createReadStream(readerpath);
            readPath.pipe(res);
        }
    });
}).listen(8081)

console.log("server is listening 8081");